package team.zero.lemon.module.sys.web;

import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.authz.annotation.AuthPermission;
import team.zero.lemon.common.config.Global;
import team.zero.lemon.common.exception.CustomException;
import team.zero.lemon.common.mapper.JsonMapper;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.sys.entity.Organization;
import team.zero.lemon.module.sys.service.OrgService;
import team.zero.lemon.module.sys.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

/**
 * Created by bolin on 2016/5/10.
 */
@Controller
@ResponseBody
@AuthPassport
@RequestMapping(value = "${adminPath}/sys/org", method = {RequestMethod.POST, RequestMethod.GET})
public class OrgController  extends BaseController {
    @Autowired
    private OrgService orgService;
    @AuthPassport
    @RequestMapping("/user/query/all")
    @AuthPermission("sys:user:view")
    public List<Organization> findAllOrgUser(@RequestBody Organization organization) {
        return orgService.findAllOrgUser(organization);
    }
    
    @AuthPassport
    @RequestMapping("/query/all")
    public List<Organization> findAllOrg() {
        return orgService.findAllOrg();
    }

    @AuthPassport
    @RequestMapping("/query/page/parentId")
    @AuthPermission("sys:org:view")
    public Page<Organization> findOrgByParentId(@RequestBody Organization organization) {
        return orgService.findOrgByParentId(organization);
    }

    @AuthPassport
    @RequestMapping("/save")
    @AuthPermission("sys:org:edit")
    public int SaveOrg(@RequestBody Organization organization) {
        return orgService.save(organization);
    }

    @AuthPassport
    @RequestMapping("/delete/ids")
    @AuthPermission("sys:org:delete")
    public int deleteOrg(@RequestBody Organization organization) {
        return orgService.deleteLogicMulti(organization);
    }

    @AuthPassport
    @RequestMapping("/findportinfo")
    public List<Organization> findPortInfo() {
        return orgService.findPortInfo();
    }

    @AuthPassport
    @RequestMapping("/findPortAndWarehouse")
    public List<Organization> findPortAndWarehouse() {
        return orgService.findPortAndWarehouse();
    }

    @AuthPassport
    @RequestMapping("/findWarehouse")
    public List<Organization> findWarehouse() {
        return orgService.findPortAndWarehouse();
    }
}
